var WebSocket = WebSocket || window.WebSocket || window.MozWebSocket;

var CommandEvents  = {
   Login:101,
};

var Encode = function(obj) {
    return JSON.stringify(obj);
};
var Decode = function(obj) {
    return JSON.parse(obj);
};

var ws;

var MinesConstants = {
    initData: function () {
        this.MAX_ROW = 10;
        this.MAX_COL = 9;
        this.DIS_MINE_COL = 76;
        this.DIS_MINE_ROW = 65;
        this.MINE = -1;
        this.testWebSocket();
    },

    testWebSocket:function()
    {
        //var config = {
        //    event:CommandEvents.LOGIN,
        //    username:"nihaoa"
        //};
        //var message = Encode(config);
        //try {
        //    ws = new WebSocket("ws://localhost:8888/ws");
        //    ws.onopen = function() {
        //
        //        console.log("onopen"+ e.data);
        //        ws.send(message);
        //
        //    };
        //    ws.onmessage = function (e) {
        //        console.log("app->srv.ws.onmessage():"+e.data);
        //        if(e.data!==null || e.data !== 'undefined')
        //        {
        //            var jsonFromClient = Decode(e.data);
        //            if(jsonFromClient.event === CommandEvents.LOGIN_DONE)
        //            {
        //                //enterWorldScene = new EnterWorldScene(jsonFromClient);
        //                //cc.director.runScene(enterWorldScene);
        //                console.log("--------");
        //            }
        //        }
        //    };
        //    ws.onclose = function (e) {
        //        console.log("onclose"+ e.data);
        //    };
        //    ws.onerror = function (e) {
        //        console.log("onerror"+ e.data);
        //    };
        //} catch (e) {
        //    console.error(e.data);
        //}

        //ws = new WebSocket('ws://localhost:8080');



        //ws = new WebSocket('ws://localhost:8080/websocket');
        ////ws = new WebSocket('ws://localhost:8083/websocket/?request=e2lkOjE7cmlkOjI2O3Rva2VuOiI0MzYwNjgxMWM3MzA1Y2NjNmFiYjJiZTExNjU3OWJmZCJ9');
        //ws.onopen = function()
        //{
        //    console.log('---------------open');
        //    ws.send('hello');
        //};
        //ws.onmessage = function(evt)
        //{
        //    console.log('---------------onmessage');
        //    console.log(evt.data)
        //};
        //ws.onclose = function(evt)
        //{
        //    console.log('-------------WebSocketClosed!'+evt.data);
        //};
        //ws.onerror = function(evt)
        //{
        //    console.log('--------------------WebSocketError!'+evt.data);
        //};

    },
};

MinesConstants.initData();
module.exports = MinesConstants;